package com.thoughtworks;

import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws IOException {
        int t = 1;
        String name;

        welcomeMessage();
        while (t == 1) {
            System.out.println();
            menu();

            int choice=getChoice();

            if (choice==1) {
                System.out.format("%-50s%-50s%-50s", "Book Name", "Author Name", "Year of Publication");
                System.out.println();
                System.out.println();
            }
            ChooseAnOption.action(choice);

            checkoutOrReturn();


            Scanner input = new Scanner(System.in);
            int c=input.nextInt();
            switch (c) {
                case 1:
                    System.out.println();
                    System.out.println("Enter the name of the book that you want to checkout");
                    Scanner key = new Scanner(System.in);
                    name = key.nextLine();
                    int checkout=BookCheckout.checkOut(name);
                    if(checkout==1)
                        System.out.println("Thankyou! Enjoy the book..");
                    else
                        System.out.println("That book is not available..");
                    break;
                case 2:
                    System.out.println();
                    System.out.println("Enter the name of the book that you want to return");
                    Scanner keyboard = new Scanner(System.in);
                    name=keyboard.nextLine();
                    int returnbook=Return.returnBook(name);
                    if(returnbook==1)
                        System.out.println("Successful Return");
                    else
                        System.out.println("Unsuccessful Return");
                    break;
                default:
                    System.out.println();
            }
        }
        }


    public static void welcomeMessage() {
        System.out.println("        WELCOME TO BIBLIOTECA!      ");
        System.out.println("------------------------------------");
    }

    public static void menu() {
        System.out.println("Choose your action");
        System.out.println("    1. List Books") ;
        System.out.println("    2. Quit") ;
        System.out.println("Select a valid option");

    }

    public static void checkoutOrReturn()
    {
        System.out.println();
        System.out.println("Enter your choice");
        System.out.println("    1.Checkout a book");
        System.out.println("    2.Return a book");

    }

    public static void displayBooks(Books obj)
    {
        System.out.format("%-50s%-50s%-50d", obj.bookName, obj.authorName, obj.yearOfPublication);
        System.out.print("\n");
    }
       public static int getChoice() {
           Scanner in = new Scanner(System.in);
           int yourChoice = in.nextInt();
           return yourChoice;
       }
}
